package net.ibizsys.eclipse.studio.data;

import java.util.ArrayList;
import java.util.List;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

/**
 * 应用
 * 
 * @author <a href='http://www.weibo.com/xjtoo' target='_blank'>Enmaai</a>
 */
public class IBizApp extends IBizData
{
	private JSONObject data;

	private String appname;
	private String pkgname;
	private List<Project> projects = new ArrayList<Project>();

	public IBizApp()
	{
	}

	public IBizApp(JSONObject json)
	{
		init(json);
	}

	@Override
	public void init(JSONObject json)
	{
		this.data = json;

		this.appname = json.getString("pssysappname");
		this.pkgname = json.getString("apppkgname");

		JSONArray projArray = json.getJSONArray("prjs");

		if (projArray != null)
		{
			for (int i = 0; i < projArray.size(); i++)
			{
				JSONObject app = projArray.getJSONObject(i);

				projects.add(new Project(app,this.appname));
			}
		}
	}

	public String getAppname()
	{
		return appname;
	}

	public String getPkgname()
	{
		return pkgname;
	}

	public Object getValue(String key)
	{
		if (data.containsKey(key))
		{
			return data.get(key);
		}
		return null;
	}

	public List<Project> getProjects()
	{
		return projects;
	}

	@Override
	public String getText()
	{
		return getAppname();
	}
}